package com.foreveross.util;

import android.content.Context;
import android.content.SharedPreferences;

public class PreferencesUtil {
	private static final String PREFERENCES_NAME = "System";


	public static String getValue(Context context, String key) {
		return context.getSharedPreferences(PREFERENCES_NAME,
				Context.MODE_WORLD_READABLE).getString(key, null);
	}

	public static int getIntValue(Context context, String key) {
		return getIntValue(context, key, -1);
	}

	public static int getIntValue(Context context, String key, int defaultValue) {
		return context.getSharedPreferences(PREFERENCES_NAME,
				Context.MODE_WORLD_READABLE).getInt(key, defaultValue);
	}

	public static void setValue(Context context, String key, String value) {
		final SharedPreferences preferences = context.getSharedPreferences(
				PREFERENCES_NAME, Context.MODE_WORLD_WRITEABLE);
		final SharedPreferences.Editor editor = preferences.edit();
		editor.putString(key, value);
		editor.commit();
	}

	public static void removeValue(Context context, String key) {
		final SharedPreferences preferences = context.getSharedPreferences(
				PREFERENCES_NAME, Context.MODE_WORLD_WRITEABLE);
		final SharedPreferences.Editor editor = preferences.edit();
		editor.remove(key);
		editor.commit();
	}

	public static void setValue(Context context, String key, int value) {
		final SharedPreferences preferences = context.getSharedPreferences(
				PREFERENCES_NAME, Context.MODE_WORLD_WRITEABLE);
		final SharedPreferences.Editor editor = preferences.edit();
		editor.putInt(key, value);
		editor.commit();
	}

	public static void clear(Context context) {
		final SharedPreferences preferences = context.getSharedPreferences(
				PREFERENCES_NAME, Context.MODE_WORLD_WRITEABLE);
		final SharedPreferences.Editor editor = preferences.edit();
		editor.clear();
		editor.commit();
	}
	public static void setBoolean(Context context, String key, boolean value) {
		final SharedPreferences preferences = context.getSharedPreferences(
				PREFERENCES_NAME, Context.MODE_WORLD_WRITEABLE);
		final SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}
	
	public static boolean getBoolean(Context context, String key, boolean defaultValue) {
		return context.getSharedPreferences(PREFERENCES_NAME,
				Context.MODE_WORLD_READABLE).getBoolean(key,defaultValue);
	}
}
